<?php
/**
 * Method
 *
 * @Description 描述
 * @Author look
 * @CreateTime 2022/2/23
 */

namespace app\common\Attributes;

use app\common\exception\ApiException;
use app\common\utils\ErrorCode;

/**
 * Class Method
 */
#[\Attribute(\Attribute::TARGET_METHOD)]
class Method {

    private $arvs;

    public function __construct(...$arv) {
        $this->arvs = $arv;
    }

    public function exec($request) {
        if (!in_array(strtoupper($request->method()), $this->arvs)) {
            throw new ApiException(...ErrorCode::METHOD_ERROR);
        }
    }

}